
use "C:\Bowra Makse Replication Dataset.dta"

*Descriptive statistics in prose
generate cohort_pct = cohort_size/chamber
tabstat cohort_pct, by(statenum)
sum rel_size
tabstat inparty_pct, by(statenum)
tab ranfor3
tab maj_chg

**Bivariate analyses
ttest static, by(cohort_large)
ttest static, by(inparty_large)
ttest static, by(nocohort)
ttest static, by(maj_lost)
tab ranfor3 cohort_large, col chi2
tab ranfor3 inparty_large, col chi2
tab ranfor3 nocohort, col chi2
tab ranfor3 maj_lost, col chi2

*Model 1
melogit static rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio|| statenum: gop
est store a2
melogit static rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio
est store a1
lrtest a1 a2

*Model 2
melogit static cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio|| state: gop
est store b2
melogit static cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio
est store b1
lrtest b1 b2

*Model 3 
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
margins, at(inparty_pct=(0.39 0.77))
margins, at(maj_lost=(0 1))

*Model 4
mprobit ranfor3 cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(state)

*Figure 1
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
margins, dydx(inparty_pct) atmeans post
estimates store c1
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
margins, dydx(maj_lost) atmeans post
estimates store c2
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==100, cl(statenum)
margins, dydx(inparty_pct) atmeans post
estimates store c3
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==100, cl(statenum)
margins, dydx(maj_lost) atmeans post
estimates store c4
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==200, cl(statenum)
margins, dydx(inparty_pct) atmeans post
estimates store c5
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==200, cl(statenum)
margins, dydx(maj_lost) atmeans post
estimates store c6

coefplot c1 c3 c5 || c2 c4 c6, mlabel format(%9.2f) mlabposition(12) mlabgap(*2) xline(0,lcolor(black))
gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
gr_edit .style.editstyle boxstyle(linestyle(color(white))) editcopy
gr_edit .plotregion1.yaxis1[1].major.num_rule_ticks = 0
gr_edit .plotregion1.yaxis1[1].edit_tick 1 1 `"Re-Election"', tickset(major)
gr_edit .plotregion1.yaxis1[1].major.num_rule_ticks = 0
gr_edit .plotregion1.yaxis1[1].edit_tick 2 2 `"Other Office"', tickset(major)
gr_edit .plotregion1.yaxis1[1].major.num_rule_ticks = 0
gr_edit .plotregion1.yaxis1[1].edit_tick 3 3 `"Retire"', tickset(major)
gr_edit .legend.plotregion1.label[1].text = {}
gr_edit .legend.plotregion1.label[1].text.Arrpush All
gr_edit .legend.plotregion1.label[2].text = {}
gr_edit .legend.plotregion1.label[2].text.Arrpush Democrats
gr_edit .legend.plotregion1.label[3].text = {}
gr_edit .legend.plotregion1.label[3].text.Arrpush Republicans
gr_edit .legend.Edit , style(cols(3)) style(rows(0)) keepstyles 
gr_edit .plotregion1.subtitle[1].text = {}
gr_edit .plotregion1.subtitle[1].text.Arrpush Cohort Compatibility
gr_edit .plotregion1.subtitle[2].text = {}
gr_edit .plotregion1.subtitle[2].text.Arrpush Majority Status Loss
gr_edit .legend.plotregion1.key[2].view.style.editstyle marker(symbol(square)) editcopy
gr_edit .legend.plotregion1.key[3].view.style.editstyle marker(symbol(triangle)) editcopy
gr_edit .legend.plotregion1.key[3].view.style.editstyle marker(fillcolor(black)) editcopy
gr_edit .legend.plotregion1.key[3].view.style.editstyle marker(linestyle(color(black))) editcopy
gr_edit .legend.plotregion1.key[2].view.style.editstyle marker(fillcolor(black)) editcopy
gr_edit .legend.plotregion1.key[2].view.style.editstyle marker(linestyle(color(black))) editcopy
gr_edit .legend.plotregion1.key[1].view.style.editstyle marker(fillcolor(black)) editcopy
gr_edit .legend.plotregion1.key[1].view.style.editstyle marker(linestyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[1].plot5.style.editstyle area(linestyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[1].plot3.style.editstyle area(linestyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[1].plot1.style.editstyle area(linestyle(color(black))) editcopy
gr_edit .legend.xoffset = 10
gr_edit .plotregion1.subtitle[1].style.editstyle fillcolor(white) editcopy
gr_edit .plotregion1.plotregion1[1].style.editstyle boxstyle(linestyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[2].style.editstyle boxstyle(linestyle(color(black))) editcopy
gr_edit .plotregion1.subtitle[1].style.editstyle linestyle(color(black)) editcopy
gr_edit .plotregion1.xaxis1[1].major.label_format = `"%9.1g"'
gr_edit .plotregion1.xaxis1[2].major.label_format = `"%9.1g"'
gr_edit .plotregion1.plotregion1[1].plot2.style.editstyle label(textstyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[1].plot4.style.editstyle label(textstyle(color(black))) editcopy
gr_edit .plotregion1.plotregion1[1].plot6.style.editstyle label(textstyle(color(black))) editcopy

*Model 5
mprobit ranfor3 maj_lost c.srty##c.srty wave margin overlap cong_overlap if within==1, cl(nameid)
margins, at(maj_lost=(0 1))

*Model 6
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead gop female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if wave_first!=2, cl(statenum)

*Table A-1
sum rel_size inparty_pct nocohort srty top_lead female gop margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio

*Table A-2 (clustered standard errors instead of multilevel)
logit static rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
logit static cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)

*Table A-3 (Split-sample models by party)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==100, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if party==200, cl(statenum)

*Table A-4 (Robustness checks)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty age top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost maj_opp c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio if tlstate==0, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire sen_size pa_ratio, cl(statenum)

*Multinomial logit versions of models
gsem (i.ranfor3 <- rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio M1[statenum]@1), mlogit
mlogit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio
mlogtest, iia
mlogtest, combine
gsem (i.ranfor3 <- cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio M1[statenum]@1), mlogit
mlogit ranfor3 cohort_large inparty_large nocohort maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio
mlogtest, iia
mlogtest, combine

*Alternative models with components of professionalism (discussed in Footnote 9)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap salary10 slength10 expend10 turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap salary10 turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap slength10 turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct maj_lost c.srty##c.srty top_lead female wave margin smideol_abs overlap cong_overlap expend10 turnover sen_size pa_ratio, cl(statenum)

*Interactions between seniority and cohort variables (discussed in Footnote 10)
mprobit ranfor3 inparty_pct maj_lost c.srty##c.rel_size top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size maj_lost c.srty##c.inparty_pct top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
mprobit ranfor3 rel_size inparty_pct c.srty##c.maj_lost top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size pa_ratio, cl(statenum)
margins, at(maj_lost=(0 1) srty=(0 12))

*Interactions between professionalism and cohort variables (discussed in Footnote 11)
mprobit ranfor3 c.rel_size##c.squire inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap turnover sen_size pa_ratio, cl(state)
mprobit ranfor3 c.inparty_pct##c.squire rel_size maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap turnover sen_size pa_ratio, cl(state)
mprobit ranfor3 c.maj_lost##c.squire rel_size inparty_pct c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap turnover sen_size pa_ratio, cl(state)

*Interacting with measure of progressive ambition opportunities (discussed in Footnote 11)
mprobit ranfor3 c.rel_size##c.pa_ratio inparty_pct maj_lost c.srty##c.srty top_lead female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size, cl(state)
mprobit ranfor3 c.inparty_pct##c.pa_ratio rel_size maj_lost c.srty##c.srty female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size, cl(state)
mprobit ranfor3 c.maj_lost##c.pa_ratio rel_size inparty_pct c.srty##c.srty female gop wave margin smideol_abs overlap cong_overlap squire turnover sen_size, cl(state)

use "C:\Bowra Makse Cohort Traits by State.dta"

*Prose regarding cohort traits by state
tabstat cohort_pct inparty_pct, by(state)

*Maps 1 and 2
maptile cohort_pct, geo(state) cutvalues(0.2 0.25 0.3)
gr_edit .legend.plotregion1.label[1].text = {}
gr_edit .legend.plotregion1.label[1].text.Arrpush Above 0.30
gr_edit .legend.plotregion1.label[2].text = {}
gr_edit .legend.plotregion1.label[2].text.Arrpush 0.25 to 0.30
gr_edit .legend.plotregion1.label[3].text = {}
gr_edit .legend.plotregion1.label[3].text.Arrpush 0.20 to 0.25
gr_edit .legend.plotregion1.label[4].text = {}
gr_edit .legend.plotregion1.label[4].text.Arrpush Below 0.20
gr_edit .legend.plotregion1.label[5].text = {}
gr_edit .legend.plotregion1.label[5].text.Arrpush Not in dataset
gr_edit .plotregion1.plot1.style.editstyle area(shadestyle(color(white))) editcopy
gr_edit .plotregion1.plot2.style.editstyle area(shadestyle(color(gs12))) editcopy
gr_edit .plotregion1.plot3.style.editstyle area(shadestyle(color(gs9))) editcopy
gr_edit .plotregion1.plot4.style.editstyle area(shadestyle(color(gs6))) editcopy
gr_edit .plotregion1.plot5.style.editstyle area(shadestyle(color(gs3))) editcopy

maptile inparty_pct , geo(state) cutvalues(0.55 0.60 0.65)
gr_edit .legend.plotregion1.label[1].text = {}
gr_edit .legend.plotregion1.label[1].text.Arrpush Above 0.65
gr_edit .legend.plotregion1.label[2].text = {}
gr_edit .legend.plotregion1.label[2].text.Arrpush 0.60 to 0.65
gr_edit .legend.plotregion1.label[3].text = {}
gr_edit .legend.plotregion1.label[3].text.Arrpush 0.55 to 0.60
gr_edit .legend.plotregion1.label[4].text = {}
gr_edit .legend.plotregion1.label[4].text.Arrpush Below 0.55
gr_edit .legend.plotregion1.label[5].text = {}
gr_edit .legend.plotregion1.label[5].text.Arrpush Not in dataset
gr_edit .plotregion1.plot1.style.editstyle area(shadestyle(color(white))) editcopy
gr_edit .plotregion1.plot2.style.editstyle area(shadestyle(color(gs12))) editcopy
gr_edit .plotregion1.plot3.style.editstyle area(shadestyle(color(gs9))) editcopy
gr_edit .plotregion1.plot4.style.editstyle area(shadestyle(color(gs6))) editcopy
gr_edit .plotregion1.plot5.style.editstyle area(shadestyle(color(gs3))) editcopy